package com.meicet.adapter.utils

import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat


fun Int.format2() = String.Companion.format("%02d", this)
fun Float.format1():String{
    return formatFloat(this,1).toString()
}
fun Float.format2() = formatFloat(this,2)
fun Double.format1() =formatDouble(this,1)
fun Double.format2() = formatDouble(this,2)
fun Double.percent() =  "${format1()} %"
fun Double.percent1() = "${format1()} %"
fun formatFloat(number: Float,index:Int): Float {
    val decimal = BigDecimal(number.toDouble())
    val rounded = decimal.setScale(index, RoundingMode.HALF_UP)
    return rounded.toFloat()
}
fun formatDouble(number: Double,index:Int): Double {
    val decimal = BigDecimal(number)
    val rounded = decimal.setScale(index, RoundingMode.HALF_UP)
    return rounded.toDouble()
}